nums=[-4,-2,-1,0,10,20,1,2,3,1,2,1]

def threeSum(nums):
    nums_len=len(nums)
    if nums_len<3:
        return []
    res=[]
    nums.sort()
    print(nums)
    #三个数肯定要先固定住一个数，去考虑另外两个数
    i=0
    while i<nums_len-2:
        l_pointer,r_pointer=i+1,nums_len-1
        while l_pointer<r_pointer:
            #退出内层循环的条件
            if nums[l_pointer]+nums[r_pointer]==-nums[i]:
                #找到了一组解
                sub=[nums[i],nums[l_pointer],nums[r_pointer]]
                if sub not in res:
                    res.append(sub)
                #左边的指针右移，右边的指针左移
                l_pointer+=1
                r_pointer-=1
            elif nums[l_pointer]+nums[r_pointer]<-nums[i]:
                #此时左右指针的加和太小了，将左指针右移
                l_pointer+=1
            else:
                r_pointer-=1
        i+=1
    return res
print(threeSum([-55,-24,-18,-11,-7,-3,4,5,6,9,11,23,33]))
